import Vue from 'vue'
import Vuex from 'vuex'
import storage from '../utils/storage'
Vue.use(Vuex)


export default new Vuex.Store({
	state: {
		userInfo: null,
		token: null,
	},
	mutations: {
		
		SAVE_USER(state, data) {
			state.userInfo = data
		},
		SAVE_TOKEN(state, data) {
			state.token = data
		},
		CLEAR_USER(state,data){
			state.token = null
			state.userInfo = null
			storage.clear()
		}
	},
	actions: {
		// login({ commit }, userInfo) {
		//   // 模拟登录请求
		//   return new Promise(resolve => {
		//     setTimeout(() => {
		//       commit('setUserInfo', userInfo)
		//       resolve()
		//     }, 1000)
		//   })
		// }
	},
	getters: {
		userInfo: state => state.userInfo,
		token: state => state.token,
	}
})